/*
	created time:2018/4/4
	author:Chason
	describe:头部容器,包含钻石,欢乐豆等等(首页)
*/
class Header extends egret.Sprite {
	private constructor() {
		super();
		this.initHeader();
		//监听添加到显示列表
		this.addEventListener(egret.Event.ADDED_TO_STAGE, () => {
			this.start();
		}, this);
	}
	//舞台宽度高度
	private stageWidth = egret.MainContext.instance.stage.stageWidth;
	private stageHeight = egret.MainContext.instance.stage.stageHeight;

	//初始化
	private headerHeight = 90;//实际高度80,多出来10为溢出在顶部
	private headHidHig = -10;//隐藏10在顶部,防止header动画过程离开了顶部(不好看)
	public initHeader(): void {
		this.y = this.headHidHig;//让header隐藏10在顶部,防止header动画过程离开了顶部(不好看)
		//绘制背景
		let headerBg=new HeaderBackground();
		headerBg.width = this.stageWidth;
	    headerBg.height = this.headerHeight;
		this.addChild(headerBg);
		//退出按钮
		this.addChild(this.outBtn());
		//钻石
		this.addChild(this.diamonds());
		//欢乐豆
		this.addChild(this.bean());
	}

	//退出的按钮
	private outBtn(): egret.Bitmap {
		let outImg: egret.Bitmap = new egret.Bitmap();
		outImg.texture = RES.getRes("home_json.signOut");
		outImg.x = 70;
		outImg.y = 20;
		return outImg;
	}
	//钻石数量
	private diamonds() {
		let wrap:HeaderDiamonds= new HeaderDiamonds();
		wrap.x = this.stageWidth - 320;
		wrap.y = 25;
		return wrap;
	}

	//欢乐豆
	private bean() {
		let wrap: HeaderGlod = new HeaderGlod();
		wrap.x = this.stageWidth - 600;
		wrap.y = 25;
		return wrap;
	}

	//进入场景动画
	public start(): void {
		let header = egret.Tween.get(this);
		header.to({ y: -this.headerHeight })
			.to({ y: this.headHidHig }, 500, egret.Ease.backOut);
	}


	//单例模式
	public static header: Header;
	public static getInstance(): Header {	
		if(!this.header){
			this.header=new Header();
		}	
		return this.header;
	}
}